/*
 * Copyright 2011 Marcos Fabio Pereira
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.moveme.examples.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.moveme.MoveMeClient;
import com.moveme.MoveMeListener;
import com.moveme.network.payload.PSPayload;
import com.moveme.network.payload.state.PSMoveState;

/**
 * MoveMe UI Console.
 * 
 * @author Marcos Fabio Pereira
 * 
 */
public class JMoveMeConsole extends JFrame implements ActionListener,
        ChangeListener, MoveMeListener {

    /**
     * JPanel that host the camera view.
     */
    private JPanel cameraJPanel;

    /**
     * The MoveMeClient instance.
     */
    private MoveMeClient moveMeClient;

    /**
     * JPanel that host the position information about move controllers.
     */
    private JPanel spherePanel;

    /**
     * Move controller selected.
     */
    private short moveControllerSelected = 0;
    private JLabel lblPositionW;
    private JLabel lblPositionZ;
    private JLabel lblPositionY;
    private JLabel lblPositionX;

    private JLabel lblVelX;
    private JLabel lblVelY;
    private JLabel lblVelZ;
    private JLabel lblVelW;

    private JLabel lblAccelX;
    private JLabel lblAccelY;
    private JLabel lblAccelZ;
    private JLabel lblAccelW;

    private JLabel lblHandlePosX;
    private JLabel lblHandlePosY;
    private JLabel lblHandlePosZ;
    private JLabel lblHandlePosW;

    private JLabel lblHandleVelX;
    private JLabel lblHandleVelY;
    private JLabel lblHandleVelZ;
    private JLabel lblHandleVelW;

    private JLabel lblHandleAccelX;
    private JLabel lblHandleAccelY;
    private JLabel lblHandleAccelZ;
    private JLabel lblHandleAccelW;

    private JColorChooser sphereColorChooser;
    private JLabel lblQuatW;
    private JLabel lblQuatZ;
    private JLabel lblQuatY;
    private JLabel lblQuatX;
    private JTextField ipServer;

    /**
     * Create the panel.
     */
    public JMoveMeConsole() {
        setMaximumSize(new Dimension(1080, 640));
        setMinimumSize(new Dimension(1080, 640));
        setSize(new Dimension(1080, 640));
        setTitle("MoveMe Console");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setAlwaysOnTop(true);
        setPreferredSize(new Dimension(1080, 640));
        getContentPane().setLayout(null);

        JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        tabbedPane.setBounds(202, 15, 852, 552);
        tabbedPane.addChangeListener(this);
        getContentPane().add(tabbedPane);

        JPanel cameraPanel = new JPanel();
        cameraPanel.setName("cameraPanel");
        tabbedPane.addTab("Camera", null, cameraPanel, null);
        tabbedPane.setBackgroundAt(0, new Color(192, 192, 192));
        cameraPanel.setLayout(null);

        cameraJPanel = new JPanel();
        cameraJPanel.setBounds(3, 5, 617, 480);
        cameraJPanel.setPreferredSize(new Dimension(640, 480));
        cameraPanel.add(cameraJPanel);

        JButton btnStartCapture = new JButton("Start capture");
        btnStartCapture.setBounds(656, 233, 181, 23);
        cameraPanel.add(btnStartCapture);
        btnStartCapture.setActionCommand("startCapture");
        btnStartCapture.addActionListener(this);

        JButton btnStopCapture = new JButton("Stop capture");
        btnStopCapture.setBounds(658, 267, 179, 23);
        cameraPanel.add(btnStopCapture);
        btnStopCapture.setActionCommand("stopCapture");
        btnStopCapture.addActionListener(this);

        spherePanel = new JPanel();
        tabbedPane.addTab("Sphere (position, vel, accel)", null, spherePanel,
                null);
        spherePanel.setLayout(null);

        lblPositionX = new JLabel("0.0000");
        lblPositionX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblPositionX.setBounds(133, 70, 142, 33);
        spherePanel.add(lblPositionX);

        JLabel lblCoordX = new JLabel("Coord X:");
        lblCoordX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblCoordX.setBounds(28, 70, 100, 33);
        spherePanel.add(lblCoordX);

        JLabel lblCoordY = new JLabel("Coord Y:");
        lblCoordY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblCoordY.setBounds(28, 108, 100, 33);
        spherePanel.add(lblCoordY);

        lblPositionY = new JLabel("0.0000");
        lblPositionY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblPositionY.setBounds(133, 108, 142, 33);
        spherePanel.add(lblPositionY);

        JLabel lblCoordZ = new JLabel("Coord Z:");
        lblCoordZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblCoordZ.setBounds(28, 146, 100, 33);
        spherePanel.add(lblCoordZ);

        lblPositionZ = new JLabel("0.0000");
        lblPositionZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblPositionZ.setBounds(133, 146, 142, 33);
        spherePanel.add(lblPositionZ);

        JLabel lblCoordW = new JLabel("Coord W:");
        lblCoordW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblCoordW.setBounds(28, 185, 100, 33);
        spherePanel.add(lblCoordW);

        lblPositionW = new JLabel("0.0000");
        lblPositionW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblPositionW.setBounds(133, 185, 142, 33);
        spherePanel.add(lblPositionW);

        lblVelW = new JLabel("0.0000");
        lblVelW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblVelW.setBounds(390, 185, 135, 33);
        spherePanel.add(lblVelW);

        lblVelZ = new JLabel("0.0000");
        lblVelZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblVelZ.setBounds(390, 146, 135, 33);
        spherePanel.add(lblVelZ);

        lblVelY = new JLabel("0.0000");
        lblVelY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblVelY.setBounds(390, 108, 135, 33);
        spherePanel.add(lblVelY);

        lblVelX = new JLabel("0.0000");
        lblVelX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblVelX.setBounds(390, 70, 135, 33);
        spherePanel.add(lblVelX);

        JLabel label_10 = new JLabel("Coord X:");
        label_10.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_10.setBounds(285, 70, 95, 33);
        spherePanel.add(label_10);

        JLabel label_11 = new JLabel("Coord Y:");
        label_11.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_11.setBounds(285, 108, 95, 33);
        spherePanel.add(label_11);

        JLabel label_13 = new JLabel("Coord Z:");
        label_13.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_13.setBounds(285, 146, 95, 33);
        spherePanel.add(label_13);

        JLabel label_15 = new JLabel("Coord W:");
        label_15.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_15.setBounds(285, 185, 95, 33);
        spherePanel.add(label_15);

        JLabel label_1 = new JLabel("Coord W:");
        label_1.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_1.setBounds(553, 185, 100, 33);
        spherePanel.add(label_1);

        JLabel label_2 = new JLabel("Coord Z:");
        label_2.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_2.setBounds(553, 146, 100, 33);
        spherePanel.add(label_2);

        JLabel label_4 = new JLabel("Coord Y:");
        label_4.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_4.setBounds(553, 108, 100, 33);
        spherePanel.add(label_4);

        JLabel label_6 = new JLabel("Coord X:");
        label_6.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_6.setBounds(553, 70, 100, 33);
        spherePanel.add(label_6);

        lblAccelX = new JLabel("0.0000");
        lblAccelX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblAccelX.setBounds(658, 70, 115, 33);
        spherePanel.add(lblAccelX);

        lblAccelY = new JLabel("0.0000");
        lblAccelY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblAccelY.setBounds(658, 108, 115, 33);
        spherePanel.add(lblAccelY);

        lblAccelZ = new JLabel("0.0000");
        lblAccelZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblAccelZ.setBounds(658, 146, 115, 33);
        spherePanel.add(lblAccelZ);

        lblAccelW = new JLabel("0.0000");
        lblAccelW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblAccelW.setBounds(658, 185, 115, 33);
        spherePanel.add(lblAccelW);

        JLabel lblPosition = new JLabel("Position");
        lblPosition.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblPosition.setBounds(67, 11, 80, 33);
        spherePanel.add(lblPosition);

        JLabel lblVelocity = new JLabel("Velocity");
        lblVelocity.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblVelocity.setBounds(323, 11, 80, 33);
        spherePanel.add(lblVelocity);

        JLabel lblAccel = new JLabel("Accel");
        lblAccel.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblAccel.setBounds(594, 11, 80, 33);
        spherePanel.add(lblAccel);

        JPanel handlePanel = new JPanel();
        handlePanel.setLayout(null);
        tabbedPane.addTab("Handle (position, vel, accel) and Orientation",
                null, handlePanel, null);

        lblHandlePosX = new JLabel("0.0000");
        lblHandlePosX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandlePosX.setBounds(140, 58, 132, 33);
        handlePanel.add(lblHandlePosX);

        JLabel label_7 = new JLabel("Coord X:");
        label_7.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_7.setBounds(35, 58, 100, 33);
        handlePanel.add(label_7);

        JLabel label_9 = new JLabel("Coord Y:");
        label_9.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_9.setBounds(35, 96, 100, 33);
        handlePanel.add(label_9);

        lblHandlePosY = new JLabel("0.0000");
        lblHandlePosY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandlePosY.setBounds(140, 96, 132, 33);
        handlePanel.add(lblHandlePosY);

        JLabel label_12 = new JLabel("Coord Z:");
        label_12.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_12.setBounds(35, 134, 100, 33);
        handlePanel.add(label_12);

        lblHandlePosZ = new JLabel("0.0000");
        lblHandlePosZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandlePosZ.setBounds(140, 134, 132, 33);
        handlePanel.add(lblHandlePosZ);

        JLabel label_14 = new JLabel("Coord W:");
        label_14.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_14.setBounds(35, 173, 100, 33);
        handlePanel.add(label_14);

        lblHandlePosW = new JLabel("0.0000");
        lblHandlePosW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandlePosW.setBounds(140, 173, 132, 33);
        handlePanel.add(lblHandlePosW);

        lblHandleVelW = new JLabel("0.0000");
        lblHandleVelW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleVelW.setBounds(388, 173, 133, 33);
        handlePanel.add(lblHandleVelW);

        lblHandleVelZ = new JLabel("0.0000");
        lblHandleVelZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleVelZ.setBounds(388, 134, 133, 33);
        handlePanel.add(lblHandleVelZ);

        lblHandleVelY = new JLabel("0.0000");
        lblHandleVelY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleVelY.setBounds(388, 96, 133, 33);
        handlePanel.add(lblHandleVelY);

        lblHandleVelX = new JLabel("0.0000");
        lblHandleVelX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleVelX.setBounds(388, 58, 133, 33);
        handlePanel.add(lblHandleVelX);

        JLabel label_16 = new JLabel("Coord W:");
        label_16.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_16.setBounds(283, 173, 100, 33);
        handlePanel.add(label_16);

        JLabel label_17 = new JLabel("Coord Z:");
        label_17.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_17.setBounds(283, 134, 100, 33);
        handlePanel.add(label_17);

        JLabel label_18 = new JLabel("Coord Y:");
        label_18.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_18.setBounds(283, 96, 100, 33);
        handlePanel.add(label_18);

        JLabel label_19 = new JLabel("Coord X:");
        label_19.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_19.setBounds(283, 58, 100, 33);
        handlePanel.add(label_19);

        lblHandleAccelW = new JLabel("0.0000");
        lblHandleAccelW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleAccelW.setBounds(646, 173, 178, 33);
        handlePanel.add(lblHandleAccelW);

        lblHandleAccelZ = new JLabel("0.0000");
        lblHandleAccelZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleAccelZ.setBounds(646, 134, 178, 33);
        handlePanel.add(lblHandleAccelZ);

        lblHandleAccelY = new JLabel("0.0000");
        lblHandleAccelY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleAccelY.setBounds(646, 96, 178, 33);
        handlePanel.add(lblHandleAccelY);

        lblHandleAccelX = new JLabel("0.0000");
        lblHandleAccelX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblHandleAccelX.setBounds(646, 58, 178, 33);
        handlePanel.add(lblHandleAccelX);

        JLabel label_24 = new JLabel("Coord X:");
        label_24.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_24.setBounds(541, 58, 100, 33);
        handlePanel.add(label_24);

        JLabel label_25 = new JLabel("Coord Y:");
        label_25.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_25.setBounds(541, 96, 100, 33);
        handlePanel.add(label_25);

        JLabel label_26 = new JLabel("Coord Z:");
        label_26.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_26.setBounds(541, 134, 100, 33);
        handlePanel.add(label_26);

        JLabel label_27 = new JLabel("Coord W:");
        label_27.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_27.setBounds(541, 173, 100, 33);
        handlePanel.add(label_27);

        JLabel label = new JLabel("Position");
        label.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label.setBounds(67, 14, 80, 33);
        handlePanel.add(label);

        JLabel label_3 = new JLabel("Velocity");
        label_3.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_3.setBounds(323, 14, 80, 33);
        handlePanel.add(label_3);

        JLabel label_5 = new JLabel("Accel");
        label_5.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_5.setBounds(594, 14, 80, 33);
        handlePanel.add(label_5);

        JLabel lblOrientationquat = new JLabel("Orientation (quat)");
        lblOrientationquat.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblOrientationquat.setBounds(55, 261, 169, 33);
        handlePanel.add(lblOrientationquat);

        JLabel label_8 = new JLabel("Coord X:");
        label_8.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_8.setBounds(35, 323, 100, 33);
        handlePanel.add(label_8);

        lblQuatX = new JLabel("0.0000");
        lblQuatX.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblQuatX.setBounds(140, 323, 132, 33);
        handlePanel.add(lblQuatX);

        lblQuatY = new JLabel("0.0000");
        lblQuatY.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblQuatY.setBounds(140, 361, 132, 33);
        handlePanel.add(lblQuatY);

        JLabel label_22 = new JLabel("Coord Y:");
        label_22.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_22.setBounds(35, 361, 100, 33);
        handlePanel.add(label_22);

        JLabel label_23 = new JLabel("Coord Z:");
        label_23.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_23.setBounds(35, 399, 100, 33);
        handlePanel.add(label_23);

        lblQuatZ = new JLabel("0.0000");
        lblQuatZ.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblQuatZ.setBounds(140, 399, 132, 33);
        handlePanel.add(lblQuatZ);

        lblQuatW = new JLabel("0.0000");
        lblQuatW.setFont(new Font("Tahoma", Font.PLAIN, 18));
        lblQuatW.setBounds(140, 438, 132, 33);
        handlePanel.add(lblQuatW);

        JLabel label_30 = new JLabel("Coord W:");
        label_30.setFont(new Font("Tahoma", Font.PLAIN, 18));
        label_30.setBounds(35, 438, 100, 33);
        handlePanel.add(label_30);

        JPanel colorSphere = new JPanel();
        colorSphere.setLayout(null);
        tabbedPane.addTab("Sphere color", null, colorSphere, null);

        sphereColorChooser = new JColorChooser();
        sphereColorChooser.setColor(Color.WHITE);
        sphereColorChooser.setBounds(new Rectangle(10, 170, 182, 362));
        sphereColorChooser.setBounds(0, 0, 532, 362);
        sphereColorChooser.getSelectionModel().addChangeListener(this);
        colorSphere.add(sphereColorChooser);

        JButton btnInitButton = new JButton("Init");
        btnInitButton.setActionCommand("init");
        btnInitButton.addActionListener(this);
        btnInitButton.setBounds(6, 64, 182, 23);
        getContentPane().add(btnInitButton);

        ButtonGroup moveControllerGroup = new ButtonGroup();

        JRadioButton moveController0RadioButton = new JRadioButton(
                "Move controller 0");
        moveController0RadioButton.setSelected(true);
        moveController0RadioButton.setBounds(6, 131, 182, 23);
        moveController0RadioButton.setActionCommand("moveController0Selected");
        moveController0RadioButton.addActionListener(this);
        getContentPane().add(moveController0RadioButton);

        JRadioButton moveController1RadioButton = new JRadioButton(
                "Move controller 1");
        moveController1RadioButton.setBounds(6, 157, 182, 23);
        moveController1RadioButton.setActionCommand("moveController1Selected");
        moveController1RadioButton.addActionListener(this);
        getContentPane().add(moveController1RadioButton);

        JRadioButton moveController3RadioButton = new JRadioButton(
                "Move controller 3");
        moveController3RadioButton.setBounds(6, 209, 182, 23);
        moveController3RadioButton.setActionCommand("moveController3Selected");
        moveController3RadioButton.addActionListener(this);
        getContentPane().add(moveController3RadioButton);

        JRadioButton moveController2RadioButton = new JRadioButton(
                "Move controller 2");
        moveController2RadioButton.setBounds(6, 183, 182, 23);
        moveController2RadioButton.setActionCommand("moveController2Selected");
        moveController2RadioButton.addActionListener(this);
        getContentPane().add(moveController2RadioButton);

        moveControllerGroup.add(moveController0RadioButton);
        moveControllerGroup.add(moveController1RadioButton);
        moveControllerGroup.add(moveController2RadioButton);
        moveControllerGroup.add(moveController3RadioButton);

        ipServer = new JTextField();
        ipServer.setBounds(6, 34, 182, 20);
        ipServer.setText(Messages.getString("MoveMeConsole.HOST"));
        getContentPane().add(ipServer);
        ipServer.setColumns(10);
        
        JLabel lblPsMoveServer = new JLabel(Messages.getString("JMoveMeConsole.lblPsMoveServer.text")); //$NON-NLS-1$
        lblPsMoveServer.setBounds(6, 15, 182, 14);
        getContentPane().add(lblPsMoveServer);
        
        JLabel lblSelectAController = new JLabel(Messages.getString("JMoveMeConsole.lblSelectAController.text")); //$NON-NLS-1$
        lblSelectAController.setBounds(10, 110, 174, 14);
        getContentPane().add(lblSelectAController);
    }

    /**
     * Get the JPanel that host the camera view.
     * 
     * @return JPanel
     */
    public JPanel getCameraJPanel() {
        return cameraJPanel;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println(e.getActionCommand());
        if (e.getActionCommand().equals("startCapture")) {
            this.moveMeClient.resumeFrame();
        } else if (e.getActionCommand().equals("stopCapture")) {
            this.moveMeClient.pauseFrame();
        } else if (e.getActionCommand().equals("init")) {
            try {
                this.moveMeClient = new MoveMeClient(this.getIpServer()
                        .getText(), Messages.getInt("MoveMeConsole.PORT"),
                        Messages.getInt("MoveMeConsole.LOCAL_PORT"), this);
                this.moveMeClient.init();
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
            }
        } else if (e.getActionCommand().equals("moveController0Selected")) {
            moveControllerSelected = 0;
        } else if (e.getActionCommand().equals("moveController1Selected")) {
            moveControllerSelected = 1;
        } else if (e.getActionCommand().equals("moveController2Selected")) {
            moveControllerSelected = 2;
        } else if (e.getActionCommand().equals("moveController3Selected")) {
            moveControllerSelected = 3;
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void notifyError(Throwable t) {
        System.out.println(t.getMessage());
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void processData(PSPayload payload) {
        PSMoveState moveState = (PSMoveState) payload;

        this.getLblQuatX()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].quat.x));
        this.getLblQuatY()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].quat.y));
        this.getLblQuatZ()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].quat.z));
        this.getLblQuatW()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].quat.w));

        this.getLblPositionX()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].pos.x));
        this.getLblPositionY()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].pos.y));
        this.getLblPositionZ()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].pos.z));
        this.getLblPositionW()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].pos.w));

        this.getLblVelX()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].vel.x));
        this.getLblVelY()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].vel.y));
        this.getLblVelZ()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].vel.z));
        this.getLblVelW()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].vel.w));

        this.getLblAccelX()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].accel.x));
        this.getLblAccelY()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].accel.y));
        this.getLblAccelZ()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].accel.z));
        this.getLblAccelW()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].accel.w));

        this.getLblHandlePosX()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handlePos.x));
        this.getLblHandlePosY()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handlePos.y));
        this.getLblHandlePosZ()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handlePos.z));
        this.getLblHandlePosW()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handlePos.w));

        this.getLblHandleVelX()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleVel.x));
        this.getLblHandleVelY()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleVel.y));
        this.getLblHandleVelZ()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleVel.z));
        this.getLblHandleVelW()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleVel.w));

        this.getLblHandleAccelX()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleAccel.x));
        this.getLblHandleAccelY()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleAccel.y));
        this.getLblHandleAccelZ()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleAccel.z));
        this.getLblHandleAccelW()
                .setText(
                        Float.toString(moveState.moveGemState[moveControllerSelected].handleAccel.w));

    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void processImage(Image imageData) {
        if (this.getCameraJPanel().isVisible()) {
            this.getCameraJPanel().getGraphics()
                    .drawImage(imageData, 0, 0, null);
        }
    }

    /**
     * Get the position panel that host the position of the enabled move
     * controllers.
     * 
     * @return JPanel position panel.
     */
    public JPanel getPositionPanel() {
        return spherePanel;
    }

    @Override
    public void stateChanged(ChangeEvent e) {
        if (e.getSource()
                .getClass()
                .equals(javax.swing.colorchooser.DefaultColorSelectionModel.class)) {
            Color newColor = this.getSphereColorChooser().getColor();
            float r = newColor.getRed() / 255.00f;
            float g = newColor.getGreen() / 255.00f;
            float b = newColor.getBlue() / 255.00f;
            System.out.println(r + " " + g + " " + b);
            this.moveMeClient.setSphereColor(moveControllerSelected, r, g, b);
        } else {
            JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
            Component component = tabbedPane.getSelectedComponent();
            if (this.getCameraJPanel() != null) {
                if (component != null) {
                    if ("cameraPanel".equals(component.getName())) {
                        this.getCameraJPanel().setVisible(true);
                    } else {
                        this.getCameraJPanel().setVisible(false);
                    }
                } else {
                    this.getCameraJPanel().setVisible(false);
                }
            }
        }

    }

    public JLabel getLblPositionW() {
        return lblPositionW;
    }

    public JLabel getLblPositionZ() {
        return lblPositionZ;
    }

    public JLabel getLblPositionY() {
        return lblPositionY;
    }

    public JLabel getLblPositionX() {
        return lblPositionX;
    }

    public JLabel getLblAccelW() {
        return lblAccelW;
    }

    public JLabel getLblAccelZ() {
        return lblAccelZ;
    }

    public JLabel getLblAccelY() {
        return lblAccelY;
    }

    public JLabel getLblAccelX() {
        return lblAccelX;
    }

    public JLabel getLblVelX() {
        return lblVelX;
    }

    public JLabel getLblVelY() {
        return lblVelY;
    }

    public JLabel getLblVelZ() {
        return lblVelZ;
    }

    public JLabel getLblVelW() {
        return lblVelW;
    }

    public JLabel getLblHandleAccelW() {
        return lblHandleAccelW;
    }

    public JLabel getLblHandleAccelZ() {
        return lblHandleAccelZ;
    }

    public JLabel getLblHandleAccelY() {
        return lblHandleAccelY;
    }

    public JLabel getLblHandleAccelX() {
        return lblHandleAccelX;
    }

    public JLabel getLblHandleVelX() {
        return lblHandleVelX;
    }

    public JLabel getLblHandleVelY() {
        return lblHandleVelY;
    }

    public JLabel getLblHandleVelZ() {
        return lblHandleVelZ;
    }

    public JLabel getLblHandleVelW() {
        return lblHandleVelW;
    }

    public JLabel getLblHandlePosX() {
        return lblHandlePosX;
    }

    public JLabel getLblHandlePosY() {
        return lblHandlePosY;
    }

    public JLabel getLblHandlePosZ() {
        return lblHandlePosZ;
    }

    public JLabel getLblHandlePosW() {
        return lblHandlePosW;
    }

    public JColorChooser getSphereColorChooser() {
        return sphereColorChooser;
    }

    public JLabel getLblQuatW() {
        return lblQuatW;
    }

    public JLabel getLblQuatZ() {
        return lblQuatZ;
    }

    public JLabel getLblQuatY() {
        return lblQuatY;
    }

    public JLabel getLblQuatX() {
        return lblQuatX;
    }

    public JTextField getIpServer() {
        return ipServer;
    }

    public static void main(String[] args) {
        JMoveMeConsole moveMeConsole = new JMoveMeConsole();
        moveMeConsole.pack();
        moveMeConsole.setVisible(true);
    }
}